public class GameState {

	public static final int ONES = 1;
	public static final int TWOS = 2;
	public static final int THREES = 3;
	public static final int FOURS = 4;
	public static final int FIVES = 5;
	public static final int SIXES = 6;
	public static final int THREE_OF_A_KIND = 7;
	public static final int FOUR_OF_A_KIND = 8;
	public static final int FULL_HOUSE = 9;
	public static final int SMALL_STRAIGHT = 10;
	public static final int LARGE_STRAIGHT = 11;
	public static final int YAHTZEE = 12;
	public static final int CHANCE = 13;
	public static final int [] CATS = {1,2,3,4,5,6,7,8,9,10,11,12,13};
	
	private int [] _data;
	private int _size;
	private int _nPlayers;

	public GameState() {
		this(1);
	}

	public GameState(int nPlayers) {
		//System.out.println("Initing gs (" + nPlayers
		_nPlayers = nPlayers;
		_data = new int[nPlayers * 14];
		for (int i=0; i<nPlayers; i++) {
			for (int j=0; j<14; j++) {
				_data[i*14 + j] = -1;
			}
		}
		_size = nPlayers * 14;
	}

	public GameState(int [] data, int nPlayers) {
		_nPlayers = nPlayers;
		_data = new int[data.length];
		System.arraycopy(data,0,_data,0,data.length);
	}

	public int getSize() {
		return _size;
	}

	public int [] getIntArray() {
		return _data;
	}

	public int getScore(int playerIndx) {
		int score = 0;
		for (int i=GameState.ONES; i<=GameState.CHANCE; i++) {
			score += (_data[playerIndx * 14 + i] > 0 ? _data[playerIndx * 14 + i] : 0);
			if (i == GameState.SIXES && score >= 63) {
				score += 35;
			}
		}
		return score;
	}

	public int getData(int playerIndx, int category) {
		if (category < 0 || category > GameState.CHANCE || playerIndx < 0 || playerIndx > _nPlayers) {
			return 9999;
		}
		return _data[playerIndx * 14 + category];
	}

	public void setData(int playerIndx, int category, int value) {
		_data[playerIndx * 14 + category] = value;
	}

	public static String hr(int category) {
		switch(category) {
			case 1: return "ONES";
			case 2: return "TWOS";
			case 3: return "THREES";
			case 4: return "FOURS";
			case 5: return "FIVES";
			case 6: return "SIXES";
			case 7: return "THREE OF A KIND";
			case 8: return "FOUR OF A KIND";
			case 9: return "FULL HOUSE";
			case 10: return "SMALL STRAIGHT";
			case 11: return "LARGE STRAIGHT";
			case 12: return "YAHTZEE";
			case 13: return "CHANCE";
			default : return "UNKNOWN";
		}

	}
	
	

}
